<template>

  <div>
    <data-table
      ref="pagingTable"
      :options="options"
      :list-query="listQuery"
    >
      <template #filter-content>

        <el-input v-model="listQuery.params.realName" placeholder="搜索人员" style="width: 200px;" class="filter-item" size="small" />
        <el-button type="primary" size="small" icon="el-icon-download" class="filter-item" @click="handleExport">导出</el-button>

      </template>

      <template #data-columns>

        <el-table-column
          label="用户名"
          prop="userName"
          align="center"
        />

        <el-table-column
          label="姓名"
          prop="realName"
          align="center"
        />

        <el-table-column
          label="考试次数"
          prop="examCount"
          align="center"
        />

        <el-table-column
          label="最高分"
          prop="maxScore"
          align="center"
          sortable="true"
        />

        <el-table-column
          label="是否通过"
          align="center"
        >
          <template v-slot="scope">

            <span v-if="scope.row.examCount===0" style="color: #ff0000;">缺考</span>
            <span v-else-if="scope.row.passed" style="color: #00ff00;">通过</span>
            <span v-else style="color: #ff0000;">未通过</span>
          </template>

        </el-table-column>

        <el-table-column
          label="操作"
          align="center"
        >
          <template v-slot="scope">
            <el-link :disabled="scope.row.examCount===0" type="primary" icon="el-icon-view" @click="showPaper(scope.row.userId)">查看试卷</el-link>
          </template>

        </el-table-column>

      </template>

    </data-table>

    <el-dialog
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      title="考试记录"
      width="60%"
      @close="dialogVisible = false"
    >
      <user-paper-list :exam-id="examId" :user-id="userId" />
    </el-dialog>

  </div>

</template>

<script>
import DataTable from '@/components/DataTable'
import { apiExportUser } from '@/api/stat/exam'
import UserPaperList from '@/views/admin/user/exam/paper'

export default {
  name: 'StatUser',
  components: { UserPaperList, DataTable },
  props: {
    examId: String
  },
  data() {
    return {

      dialogVisible: false,
      userId: '',

      listQuery: {
        current: 1,
        size: 10,
        params: {
          examId: '',
          realName: ''
        }
      },

      options: {
        // 可批量操作
        multi: false,
        // 列表请求URL
        listUrl: '/api/stat/exam/user-paging',
        keyId: 'userId'
      }
    }
  },

  created() {
    this.listQuery.params.examId = this.examId
  },
  methods: {

    // 开始考试
    showPaper(userId) {
      this.userId = userId
      this.dialogVisible = true
    },

    // 导出数据
    handleExport() {
      apiExportUser(this.listQuery.params)
    }
  }
}
</script>

<style scoped>

.el-dialog-div{
  height: 60vh;
  overflow: auto;
  padding: 10px;
}

</style>
